package com.system.comm.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class Tools {

	public static boolean isNotNull(String str){
		if(str!=null&&!str.equals("")){
			return true;
		}
		return false;
	}
	
	/**
	 * @param active_id
	 * @param num
	 * @param length
	 * @return
	 */
	public static Set<String> createCdkey(int num,int length){
		Set<String> dataSet=new HashSet<String>();
		String suffixStr=getDataStr("yyMMdd");
		long currentNum=Long.parseLong(suffixStr); 
		int  len=(currentNum+"").length(); 
		if(len>length){
			throw new RuntimeException("长度过长");
		}
		int suffixLen=length-len; 
		int i=0;
		while(i<num){
			String cdKey=currentNum+createRadomNum(suffixLen);
			if(!dataSet.contains(cdKey)){
				dataSet.add(cdKey);
				i++;
			}
		}
		return dataSet;
	}
	
	public static String createRadomNum(int lenght){
		String str = "";
		for(int i=0;i < lenght;i++){  
			int intVal=(int)(Math.random()*26+65);
			if(intVal%2==0){
				str += (char)intVal;  
			}else{
				str += (int)(Math.random()*10);
			}
		}  
		return str;
	}
	
	public static String getDataStr(String format){
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		return sdf.format(date);
	}
}
